package uit.edu.vn;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SmsRestoreServerActivity extends Activity {
    /** Called when the activity is first created. */
	private TextView header;

	private ProgressDialog loadingImageDialog;
	private Context context;
	private ListView listview;
	private Resources res;
	private List<FileObject> fileObject ;
	private List<myFile> listsms = new ArrayList<myFile>();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        context=getBaseContext();
		listview= (ListView)findViewById(R.id.listsms);
		res=getResources();
//        loadingImageDialog= new ProgressDialog(context);
//        loadingImageDialog.setMessage("Đang tải dữ liệu ....");
//        loadingImageDialog.setCancelable(false);
//        loadingImageDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        new BackgroundTask().execute();
		//load danh sach sms ve lis
		
    }
    class BackgroundTask extends AsyncTask<Void, Void, Void>
    {
    	@Override
    	protected void onPreExecute() {
    		// TODO Auto-generated method stub
    		super.onPreExecute();
//    		loadingImageDialog.show();
    	}
    	@Override
    	protected Void doInBackground(Void... params) {
    		// TODO Auto-generated method stub
    		try {
    			//hien tai lay tam userid là 2

    			Log.d("list", "load file thanh cong");
    			fileObject=WebService.getAllContactList(2);
    			for(int i =0 ; i<fileObject.size();i++)
    			{
    				Log.d("listsize", String.valueOf(fileObject.size()));
    				
    				Log.d("i", String.valueOf(i));
    				Log.d("name", fileObject.get(i).getFileName());
    				String filename=fileObject.get(i).getFileName();
    				Log.d("path", fileObject.get(i).getPathFile());
    				String path=fileObject.get(i).getPathFile();
    				Log.d("path",  String.valueOf(fileObject.get(i).getFileSize()));
    				String size=String.valueOf(fileObject.get(i).getFileSize());
    				listsms.add(new myFile(filename,path , size, res.getDrawable(R.drawable.ic_launcher)));
    				//Log.d("name", String.valueOf(listsms.get(i).getName()));
    				
    			}
    		
    			//check list sms
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}

    		return null;
    	}
    	@Override
    	protected void onPostExecute(Void result) {
    		// TODO Auto-generated method stub
//    		loadingImageDialog.dismiss();

			FileListAdapter fadapter = new FileListAdapter(context, listsms);
			listview.setAdapter(fadapter);
    		super.onPostExecute(result);
    	}
    }
	private void showToast(String string) {
		// TODO Auto-generated method stub
		Toast.makeText(context, string, Toast.LENGTH_SHORT).show();
	}
}